import type {
  CreateCrudOptionsProps,
  CreateCrudOptionsRet,
  CrudExpose,
} from '@fast-crud/fast-crud';

import type { FormRulesExt } from '#/api';
import type { IotCustomersModel } from '#/api/iot/customers/model/iotCustomersModel';

import { $t } from '@vben/locales';

import { IotCustomersApi } from '#/api/iot/customers/iotCustomers';
import { ActionEnum } from '#/enums/commonEnum';
import { indexColumn } from '#/plugins/fast-crud/common';

type ContextRef = object;

export function createCrudOptions(
  props: CreateCrudOptionsProps<
    IotCustomersModel.IotCustomersResultVO,
    ContextRef
  >,
): CreateCrudOptionsRet<IotCustomersModel.IotCustomersResultVO> {
  return {
    crudOptions: {
      request: {
        addRequest: IotCustomersApi.addRequest,
        editRequest: IotCustomersApi.editRequest,
      },
      form: {
        wrapper: {
          is: 'a-modal',
        },
      },
      addForm: { mode: 'add' },
      editForm: { mode: 'edit' },
      columns: {
        ...indexColumn(props.crudExpose),
        parentName: {
          title: $t('iot.customers.iotCustomers.parentName'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
            component: {
              disabled: true,
            },
          },
          editForm: { show: true },
          form: {
            component: {
              disabled: true,
            },
          },
          column: {
            show: true,
          },
        },
        name: {
          title: $t('iot.customers.iotCustomers.name'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        abbreviation: {
          title: $t('iot.customers.iotCustomers.abbreviation'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        contactPerson: {
          title: $t('iot.customers.iotCustomers.contactPerson'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        contactPhone: {
          title: $t('iot.customers.iotCustomers.contactPhone'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        contactEmail: {
          title: $t('iot.customers.iotCustomers.contactEmail'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        address: {
          title: $t('iot.customers.iotCustomers.address'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        longitude: {
          title: $t('iot.customers.iotCustomers.longitude'),
          type: 'number',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        latitude: {
          title: $t('iot.customers.iotCustomers.latitude'),
          type: 'number',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        businessTime: {
          title: $t('iot.customers.iotCustomers.businessTime'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: true,
          },
          editForm: { show: true },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        createdName: {
          title: $t('iot.customers.iotCustomers.createdName'),
          type: 'text',
          search: { show: false },
          addForm: {
            show: false,
          },
          editForm: { show: false },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
        createdTime: {
          title: $t('iot.customers.iotCustomers.createdTime'),
          type: 'text',
          search: { show: true },
          addForm: {
            show: false,
          },
          editForm: { show: false },
          form: {
            component: {},
          },
          column: {
            show: true,
          },
        },
      },
    },
  };
}

export const frontRules = (
  _crudExpose: CrudExpose,
  _mode: ActionEnum,
): FormRulesExt => {
  return {};
};
